package com.phkj.qdh.utils.treela;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by keranbin on 2016/8/30.
 */
public class Node {
    //id
    private String id;

    //父辈id
    private String pid = "";

    //要在树形控件上展示的内容，比如说机构名称。
    private String name;

    //树的层级
    private int level;

    // 是否是展开的
    private boolean isExpand = false;

    //是否是选择的
    private boolean isChoose=false;

    //缩进图标
    private int icon;

    //父亲节点
    private Node parent;

    //儿子节点集合
    private List<Node> children = new ArrayList<>();

    public Node(String id, String pid, String name) {
        this.id = id;
        this.pid = pid;
        this.name = name;

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    /**
     * 得到当前节点的层级，如果当前节点没有父节点，则该节点
     *是根节点，否则当前节点的层级为当前节点父节点的层级加1
     * @return
     */
    public int getLevel() {
        return parent == null ? 0 : parent.getLevel() + 1;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public boolean isExpand() {
        return isExpand;
    }

    /**
     * 设置当前节点是否展开，如果是false，那么递归关闭当前节点的所有子节点
     *
     * @param expand
     */
    public void setExpand(boolean expand) {
        isExpand = expand;
        if (!expand) {
            for (Node node : children) {
                node.setExpand(false);
            }
        }
    }

    public boolean isChoose() {
        return isChoose;
    }

    public void setChoose(boolean choose) {
        isChoose = choose;
    }

    public int getIcon() {
        return icon;
    }

    public void setIcon(int icon) {
        this.icon = icon;
    }

    public Node getParent() {
        return parent;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public List<Node> getChildren() {
        return children;
    }

    public void setChildren(List<Node> children) {
        this.children = children;
    }


    /**
     * 是否是根节点
     */
    public boolean isRoot() {
        return parent == null;
    }

    /**
     * 是否是展开状态，
     */
    public boolean isParentExpand() {
        if (parent == null)
            return false;
        return parent.isExpand();
    }


    /**
     * 是否是叶子节点
     *
     * @return
     */
    public boolean isLeft() {
        return children.size() == 0;
    }
}